package com.csx.saas.platform.init.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.csx.basic.annotation.injection.InjectionResult;
import com.csx.basic.base.service.SuperCacheServiceImpl;
import com.csx.basic.cache.model.CacheKeyBuilder;
import com.csx.saas.common.cache.init.InitProductCateCacheKeyBuilder;
import com.csx.saas.platform.init.dao.InitProductCateMapper;
import com.csx.saas.platform.init.entity.InitProductCate;
import com.csx.saas.platform.init.service.InitProductCateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 业务实现类
 * 产品分类
 * </p>
 *
 * @author ChenSongXin
 * @date 2021-03-03
 */
@Slf4j
@Service
@DS("#thread.tenant")
public class InitProductCateServiceImpl extends SuperCacheServiceImpl<InitProductCateMapper, InitProductCate> implements InitProductCateService {

    @Override
    protected CacheKeyBuilder cacheKeyBuilder() {
        return new InitProductCateCacheKeyBuilder();
    }

    protected InitProductCateService currentProxy() {
        return ((InitProductCateService) AopContext.currentProxy());
    }

    @InjectionResult
    @Override
    public InitProductCate getByIdCache(Serializable id) {
        InitProductCate initProductCate = super.getByIdCache(id);
        if(initProductCate.getParentId()!=0){
            InitProductCate parentInitProductCate = super.getByIdCache(id);
            initProductCate.setParentName(parentInitProductCate.getLabel());
        }
        return initProductCate;
    }

    @InjectionResult
    @Override
    public <E extends IPage<InitProductCate>> E page(E page, Wrapper<InitProductCate> queryWrapper) {
        return baseMapper.selectPage(page,queryWrapper);
    }

    @InjectionResult
    @Override
    public List<InitProductCate> list(Wrapper<InitProductCate> queryWrapper) {
        return baseMapper.selectList(queryWrapper);
    }
}
